package com.ltu.timkor6.gamesite.users.client;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;

public class SignOut
{
	private Users users;
	
	private UsersServiceAsync usersService = GWT.create(UsersService.class);
	
	public SignOut(Users users)
	{
		this.users = users;
	}
	
	public void sendSignOut()
	{
		// Initialize the service proxy.
		if(usersService == null)
		{
			usersService = GWT.create(UsersService.class);
		}
		
		// Set up the callback object.
		AsyncCallback<SignInStatus> callback = new AsyncCallback<SignInStatus>()
		{
			public void onFailure(Throwable caught)
			{
				Window.alert("Error: " + caught.getMessage());
			}
			
			public void onSuccess(SignInStatus status)
			{
				if(status == SignInStatus.SUCCESS)
				{
					users.checkUserInfo(null);
				}
				else
				{
					Window.alert("Signed out: " + status);
				}
			}
		};
		
		// Make the call to the stock price service.
		usersService.signOut(callback);
	}
}
